package com.elinkway.infinitemovies.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.elinkway.infinitemovies.bean.HotDownloadBean;
import com.le123.ysdq.R;

import java.util.List;

public class HotDownloadGridAdapter extends MyBaseAdapter {

	private List<HotDownloadBean> hotList;

	private class KeywordHolder {
		TextView hotSearchRankTv;
		TextView hotSearchNameTv;
	}

	public HotDownloadGridAdapter(Context context, List<HotDownloadBean> hotList) {
		super(context);
		this.hotList=hotList;
	}

	@Override
	public int getCount() {
		if(hotList.size() > 0){
			if(hotList.size() < 7){
				return hotList.size();
			}else{
				return 6;
			}
		}else{
			return 0;
		}
	}
	public void clear(){
		hotList.clear();
		notifyDataSetChanged();
	}
	
	public void resetData(List<HotDownloadBean> list) {
		hotList = list;
		notifyDataSetChanged();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		KeywordHolder holder = new KeywordHolder();
		if(convertView==null){
			convertView=inflater.inflate(R.layout.hot_searchkey_item_layout, null);
			holder.hotSearchRankTv = (TextView) convertView.findViewById(R.id.hot_rank_tv);
			holder.hotSearchNameTv = (TextView) convertView.findViewById(R.id.hot_name_tv);
			convertView.setTag(holder);
		}
		else{
			holder=(KeywordHolder) convertView.getTag();
		}
		if(position == 0){
			holder.hotSearchRankTv.setBackgroundColor(Color.parseColor("#ffff4338"));
		}else if(position == 1){
			holder.hotSearchRankTv.setBackgroundColor(Color.parseColor("#ffff8938"));
		}else if(position == 2){
			holder.hotSearchRankTv.setBackgroundColor(Color.parseColor("#ffffac38"));
		}else{
			holder.hotSearchRankTv.setBackgroundColor(Color.parseColor("#ffcccccc"));
		}
		holder.hotSearchRankTv.setText(position + 1 +"");
		holder.hotSearchNameTv.setText(hotList.get(position).getName());

		return convertView;
	}

}
